package com.ihelp.rest.mis.platform.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ihelp.rest.mis.platform.service.ModuleService;
import com.ihelp.rest.mis.pojo.Module;
import com.ihelp.rest.utils.HtmlUtil;

/**
 * 模块管理
*      
* 类名称：ModuleController   
* 类描述：     
* 创建时间：2013-3-13 下午02:11:15    
* 备注：   
* @version
 */
@Controller
@RequestMapping("/system/module")
public class ModuleController {

	@Autowired
	private ModuleService moduleService;
	
	/**
	 * 跳转模块主页面
	 * @param request
	 * @return
	 */
	@RequestMapping("module.do")
	public String loadModulePage(HttpServletRequest request){
		return "system/module/module";
	}
	
	/**
	 * 模块列表数据查询JSON
	 * @param response
	 * @param page
	 * @param rows
	 */
	@RequestMapping("findModulePage.do")
	public void findModulePage(HttpServletResponse response, int page, int rows){
		String json = this.moduleService.findPageAllModules(page, rows);
		HtmlUtil.writerJson(response, json);
	}
	
	/**
	 * 跳转模块添加页面
	 * @param request
	 * @return
	 */
	@RequestMapping("loadAddModulePage.do")
	public String loadAddModulePage(HttpServletRequest request, String uuid){
		request.setAttribute("Module", this.moduleService.getModule(uuid));
		return "system/module/addModule";
	}
	
	/**
	 * 查询父模块JSON 数据
	 * @param response
	 */
	@RequestMapping("findParentModules.do")
	public void findParentModules(HttpServletResponse response){
		String json = this.moduleService.findParentModules();
		HtmlUtil.writerJson(response, json);
	}
	
	/**
	 * 获取模块TreeData 
	 * @param response
	 */
	@RequestMapping("findModulesTreeData.do")
	public void findModulesTreeData(HttpServletResponse response){
		String json = this.moduleService.findModulesTreeData();
		HtmlUtil.writerJson(response, json);
	}
	
	/**
	 * 新增模块
	 * @param response
	 * @param module
	 */
	@RequestMapping("addModule.do")
	public void addModule(HttpServletResponse response, Module module){
		String text = this.moduleService.addModule(module);
		HtmlUtil.writerText(response, text);
	}
	
	/**
	 * 删除模块
	 * @param response
	 * @param module
	 */
	@RequestMapping("delModule.do")
	public void delModule(HttpServletResponse response, Module module){
		String text = this.moduleService.delModule(module);
		HtmlUtil.writerText(response, text);
	}
	
}
